package com.example.cloud.filter;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by wangtao on 2018/1/30.
 */
public class RouteErrorFilter extends ZuulFilter {
    private static final Logger logger = LoggerFactory.getLogger(RouteErrorFilter.class);

    @Override
    public String filterType() {
        // 返回使用的过滤器类型
        return "error";
    }

    @Override
    public int filterOrder() {
        // 决定过滤器执行顺序，不同过滤器可返回相同值
        return 0;
    }

    @Override
    public boolean shouldFilter() {
        // 是否启用过滤器
        return true;
    }

    @Override
    public Object run() {
        RequestContext ctx = RequestContext.getCurrentContext();
        ctx.getResponse().setCharacterEncoding("utf-8");
        ctx.setResponseBody("请求服务异常");
        return null;
    }
}
